﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Runda.CMS.Bll;
using Runda.CMS.Common.Entity;

namespace Runda.CMS.Portal.ContractFollowUp
{
    public partial class AccessorySettingAdd : BasePage
    {
        public int DictionaryType
        {
            get
            {
                if (Request.QueryString["Type"] != null)
                {
                    return Convert.ToInt32(Request.QueryString["Type"]);
                }
                else
                {
                    return -1;
                }
            }
        }

        public Guid ID
        {
            get 
            {
                if (Request.QueryString["ID"] != null)
                {
                    ViewState["ID"] = Request.QueryString["ID"];
                    return new Guid(ViewState["ID"].ToString());
                }
                else if (ViewState["ID"] != null)
                {
                    return new Guid(ViewState["ID"].ToString());
                }

                return Guid.Empty;
            }
            set { ViewState["ID"] = value; }
        }
        public override bool IsCheckAccessible
        {
            get
            {
                return false;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (ID != Guid.Empty)
                {

                    MasterDataBll dictionaryBll = new MasterDataBll();
                    SysDictionaryEntity dictionary = null;
                    dictionary = dictionaryBll.Get<SysDictionaryEntity>(ID);
                    if (dictionary != null)
                    {
                        txtName.Text = dictionary.Name;
                    }
                }
            }
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        { 
            MasterDataBll dictionaryBll = new MasterDataBll();
            SysDictionaryEntity dictionary = null;

            if (ID != Guid.Empty)
            {
                dictionary = dictionaryBll.Get<SysDictionaryEntity>(ID);
            }
            else
            {
                dictionary = new SysDictionaryEntity();
                dictionary.CreatedBy = base.CurrentUserEntity.UserID;
                dictionary.CreatedOn = DateTime.Now;
                dictionary.Type = DictionaryType;
            }

            dictionary.Name = txtName.Text;
            dictionary.Deleted = false;
            dictionaryBll.InsertOrUpdate(dictionary);

            ClientScript.RegisterStartupScript(this.GetType(), "success", "SaveAndCloseWindow();", true);
        }
    }
}
